package org.example.cet.demos.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.example.cet.demos.converter.converter;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.dto.StudentsDto;
import org.example.cet.demos.domain.po.Student;
import org.example.cet.demos.domain.query.StudentQuery;
import org.example.cet.demos.mapper.StudentMapper;
import org.example.cet.demos.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@Service
@RequiredArgsConstructor
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {
    private final converter converter;

    public PageBean getPage(StudentQuery studentQuery){
        Page<Student> page=new Page<>(studentQuery.getCurrentPage(), studentQuery.getPageSize());
        lambdaQuery().like(studentQuery.getId()!=null,Student::getId,studentQuery.getId())
                .like(studentQuery.getIdCard()!=null,Student::getIdCard,studentQuery.getIdCard())
                .like(!StrUtil.isBlankIfStr(studentQuery.getName()),Student::getName,studentQuery.getName())
                .like(!StrUtil.isBlankIfStr(studentQuery.getGender()),Student::getGender,studentQuery.getGender())
                .like(!StrUtil.isBlankIfStr(studentQuery.getCollege()),Student::getCollege,studentQuery.getCollege())
                .like(studentQuery.getGrade()!=null,Student::getGrade,studentQuery.getGrade())
                .like(!StrUtil.isBlankIfStr(studentQuery.getMajor()),Student::getMajor,studentQuery.getMajor())
                .like(studentQuery.getClassId()!=null,Student::getClassId,studentQuery.getClassId())
                .like(studentQuery.getTeachId()!=null,Student::getTeachId,studentQuery.getTeachId())
                .page(page);
        PageBean pageBean=new PageBean();
        pageBean.setTotal(page.getTotal());
        pageBean.setRows(page.getRecords());
        return pageBean;
    }

    @Autowired
    private StudentMapper studentMapper;
    public List<StudentsDto> getList(){
        return studentMapper.getList();
    }

}
